package io;

import java.io.File;
import javax.swing.JFileChooser;

import view.Designer;

/**
 * A class to model the open dialog box for opening files.
 * @author Daniel Bond, Mohammed Abdullah, Gideon Pyzer
 *
 */
public class FileOpenDialog
{	
	private JFileChooser chooser;

	public FileOpenDialog(File baseFolder){
		if (!baseFolder.isDirectory()){
			baseFolder = new File(".");
		}
		chooser = new JFileChooser(baseFolder);
		chooser.addChoosableFileFilter(new OpenFileFilter());
		chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

	}



	/**
	 * Opens the dialog window
	 * @return the first selected file from the dialog window
	 */
	public File show(){
		int returnVal = chooser.showOpenDialog(Designer.getInstance());
		if(returnVal == JFileChooser.APPROVE_OPTION) {
			return chooser.getSelectedFile();
		}
		return null;

	}
}
